﻿using BLL;
using Config;
using gfLibrary;
using Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace IYAKASAPortal.PrintAll
{
    public partial class PrintHBSYList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {
                btnSearch_Click(sender, e);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string strKeywords = txtKeywords.Text;

            string strSql = "  select ID,JCLSH,JCCS,HPHM,VIN,HPZL, (select CON_CON from CONST_DEFINE where CON_CHNAME='JYXM' and CON_CODE=SUBSTRING(JYXM,1,LEN(JYXM)-1)) as JCFF,CLXXSJ, (case Z_PD when '1' then '合格' when '2' then '不合格' else '未判定' end) as JG from RESULT_VEHICLE_INFO WHERE substring(JCLSH,1,1)='P'";
            if (strKeywords.Length > 0)
            {   
                strSql += "  AND ( ";
                strSql += " HPHM like '%" + strKeywords + "%'";
                strSql += " or VIN like '%" + strKeywords + "%'";
                strSql += " or JCLSH like '%" + strKeywords + "%')";
            }

            strSql += " order by ID desc";

            DataTable m_dtTable = new DataTable();
            GreatPager1.BindDataTablePage(ref m_dtTable, AppConfig.g_strConnectionStringSqlClient, strSql, 20);

            rptList.DataSource = m_dtTable;
            rptList.DataBind();

            m_dtTable.Dispose();
        }

        protected void btnSearchAll_Click(object sender, EventArgs e)
        {
            txtKeywords.Text = "";
            btnSearch_Click(sender, e);
        }

        protected void GreatPager1_PageIndexChanging(object sender, gfPage.PagerEventArgs e)
        {
            GreatPager1.PageIndex = e.NewPageIndex;

            DataTable m_dtTable = GreatPager1.BindDataTablePage();
            rptList.DataSource = m_dtTable;
            rptList.DataBind();
        }

        protected void btnPrintHBSY_Click(object sender, EventArgs e)
        {
            string strUniqueKey = Request.Form["txtUniqueKey"];

            if ((strUniqueKey == null) || (strUniqueKey.Length == 0) || (gfValidate.Is_Integer(strUniqueKey) == false))
            {
                gfAjaxJs.SetAlertMsg(this.UpdatePanel1, "请选择一条记录！");
                return;
            }
            RESULT_VEHICLE_INFO_BLL vehiclebll = new RESULT_VEHICLE_INFO_BLL();
            var vehicle = vehiclebll.GetModelList("ID=" + strUniqueKey);
            string JYXM = vehicle[0].JYXM;

            bool bIsOpenPage = false;
            CONST_DEFINE_WEB_BLL const_web_bll = new CONST_DEFINE_WEB_BLL();
            var const_web = const_web_bll.GetModelList("CategoryID=12");
            if (const_web.Length > 0)
            {
                if (string.IsNullOrEmpty(const_web[0].ValueOfName) == false)
                {
                    if (const_web[0].ValueOfName == "1")
                    {
                        bIsOpenPage = true;
                    }

                }
            }

            if (bIsOpenPage)
            {
                if (JYXM == "X1,")
                {
                    gfLibrary.gfAjaxJs.OpenNewUrl(this.UpdatePanel1, "PrintPF_X1_SDS.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X3,")
                {
                    gfLibrary.gfAjaxJs.OpenNewUrl(this.UpdatePanel1, "PrintPF_X3_VMAS.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X4,")
                {
                    gfLibrary.gfAjaxJs.OpenNewUrl(this.UpdatePanel1, "PrintPF_X4_BTG.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X6,")
                {
                    gfLibrary.gfAjaxJs.OpenNewUrl(this.UpdatePanel1, "PrintPF_X6_LZ.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X5,")
                {
                    gfLibrary.gfAjaxJs.OpenNewUrl(this.UpdatePanel1, "PrintPF_X5_JZJS.aspx?UniqueKey=" + strUniqueKey);
                }
            }
            else
            {
                if (JYXM == "X1,")
                {
                    Response.Redirect("PrintPF_X1_SDS.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X3,")
                {
                    Response.Redirect("PrintPF_X3_VMAS.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X4,")
                {
                    Response.Redirect("PrintPF_X4_BTG.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X6,")
                {
                    Response.Redirect("PrintPF_X6_LZ.aspx?UniqueKey=" + strUniqueKey);
                }
                else if (JYXM == "X5,")
                {
                    Response.Redirect("PrintPF_X_JZJS.aspx?UniqueKey=" + strUniqueKey);
                }
            }
        }
    }
}